package org.zdc.pivot.wtk.skin;
import org.zdc.core.IllegalArgumentException;
import org.zdc.pivot.wtk.Cursor;
import org.zdc.pivot.wtk.IDragSource;
import org.zdc.pivot.wtk.IDropTarget;
import org.zdc.pivot.wtk.IMenuHandler;
import org.zdc.pivot.wtk.KeyLocation;
import org.zdc.pivot.wtk.listener.IComponentListener;
import org.zdc.pivot.wtk.listener.IComponentStateListener;
import org.zdc.pivot.wtk.listener.IComponentMouseListener;
import org.zdc.pivot.wtk.listener.IComponentMouseButtonListener;
import org.zdc.pivot.wtk.listener.IComponentMouseWheelListener;
import org.zdc.pivot.wtk.listener.IComponentKeyListener;
import org.zdc.pivot.wtk.listener.IComponentTooltipListener;
import org.zdc.pivot.wtk.Mouse;
import org.zdc.pivot.wtk.Component;
import org.zdc.pivot.wtk.MouseButton;
import org.zdc.pivot.wtk.MouseScrollType;

class ComponentSkin implements ISkin, 
					implements IComponentListener, 
					implements IComponentStateListener, 
					implements IComponentMouseListener, 
					implements IComponentMouseButtonListener, 
					implements IComponentMouseWheelListener, 
					implements IComponentKeyListener, 
					implements IComponentTooltipListener
{

	private var component:Component = null;
	
	private var width:Float;
	private var height:Float;
	
	public function new() 
	{
		width = 0;
		height = 0;
	}
	
	public function getWidth():Float {
		return width;
	}
	
	public function getHeight():Float {
		return height;
	}
	
	public function setSize(width:Float, height:Float):Void {
		this.width = width;
		this.height = height;
	}
	
	public function getPreferredSize():Dimensions {
		return new Dimensions(getPreferredWidth(-1), getPreferredHeight(-1));
	}
	
	public function getBaseline(?width:Float, ?height:Float):Float {
		return -1;
	}
	
	public function install(c:Component):Void {
		if (this.component != null) {
			throw new IllegalArgumentException("Skin is already installed on a component.");
		}
		
		c.getComponentListeners().add(this);
        c.getComponentStateListeners().add(this);
        c.getComponentMouseListeners().add(this);
        c.getComponentMouseButtonListeners().add(this);
        c.getComponentMouseWheelListeners().add(this);
        c.getComponentKeyListeners().add(this);
        c.getComponentTooltipListeners().add(this);
		
		this.component = c;
	}
	
	public function getComponent():Component {
		return component;
	}
	
	/**
	 * 默认皮肤可以接受焦点
	 * @return
	 */
	public function isFocusable():Bool {
		return true;
	}
	
	/**
	 * 默认skin假定为不透明
	 * @return
	 */
	public function isOpaque():Bool {
		return true;
	}
	
	public function layout():Void {
		
	}
	
	public function paint():Void {
		
	}
	
	public function parentChanged(c:Component, prevPar:Container):Void {
		
	}
	
	public function sizeChanged(c:Component, previousWidth:Float, previousHeight:Float):Void {
		
    }

    public function preferredSizeChanged(c:Component, previousPreferredWidth:Float, previousPreferredHeight:Float):Void {
		
    }
	
	public function widthLimitsChanged(c:Component, prevMinWid:Float, prevMaxWid:Float):Void {
		
	}
	
	public function heightLimitsChanged(c:Component, prevMinHei:Float, prevMaxHei:Float):Void {
		
	}
	
	public function locationChanged(c:Component, prevX:Float, prevY:Float):Void {
		
	}
	
	public function visibleChanged(c:Component):Void {
		
	}
	
	public function cursorChanged(c:Component, prevCur:Cursor):Void {
		
	}
	
	public function tooltipTextChanged(c:Component, prevTooltipText:String):Void {
		
	}
	
	public function tooltipDelayChanged(c:Component, prevTooltipDelay:Int):Void {
		
	}
	
	public function dragSourceChanged(c:Component, previousDragSource:IDragSource):Void {
		
	}
	
	public function dropTargetChanged(c:Component, previousDropTarget:IDropTarget):Void {
		
	}
	
	public function menuHandlerChanged(c:Component, previousMenuHandler:IMenuHandler):Void {
		
	}
	
	public function nameChanged(c:Component, previousName:String):Void {
		
	}
	
	public function enabledChanged(c:Component):Void {
		
	}
	
	public function focusedChanged(c:Component, obverseComponent:Component):Void {
		
	}
	
	public function mouseMove(c:Component, x:Float, y:Float):Bool {
		return false;
	}
	
	public function mouseOver(c:Component):Void {
		
	}
	
	public function mouseOut(c:Component):Void {
		
	}
	
	public function mouseDown(c:Component, button:MouseButton, x:Float, y:Float):Bool {
		return false;
	}
	
	public function mouseUp(c:Component, button:MouseButton, x:Float, y:Float):Bool {
		return false;
	}
	
	public function mouseClick(c:Component, button:MouseButton, x:Float, y:Float, count:Int):Bool {
		return false;
	}
	
	public function mouseWheel(c:Component, scrollType:MouseScrollType, scrollAmount:Int, wheelRotation:Int, x:Float, y:Float):Bool {
		return false;
	}
	
	public function keyTyped(c:Component, character:String):Void {
		
	}
	
	public function keyPressed(c:Component, keyCode:Int, keyLocation:KeyLocation):Bool {
		return false;
	}
	
	public function keyReleased(c:Component, keyCode:Int, keyLocation:KeyLocation):Bool {
		return false;
	}
	
	public function tooltipTriggered(c:Component, x:Float, y:Float):Void {
		
	}
	
	public function invalidateComponent():Void {
		if (component != null) {
            component.invalidate();
            component.repaint();
        }
	}
	
	public function repaintComponent(?immediate:Bool):Void {
		
	}
	
	public static function decodeFont(value:String):Void {
		
	}
	
	public function getPreferredWidth(height:Float):Float {
		return -1;
	}
	
	public function getPreferredHeight(width:Float):Float {
		return -1;
	}
	
}